<?php
/**
 * Created by PhpStorm.
 * User: 35083
 * Date: 2019/7/5
 * Time: 10:34
 */

namespace app\admin\mapper;


class Ad
{
    static private $instance = null;

    static public function getInstance()
    {
        //判断$instance是否是Uni的对象
        //没有则创建
        if (self::$instance == null) {
            self::$instance = new self();
        }
        return self::$instance;

    }

    public $positionLists = array();
    public $optypeLists = array();

    /**
     * @return array
     */
    public function getPositionLists()
    {
        return $this->positionLists;
    }

    /**
     * @param array $positionLists
     */
    public function setPositionLists($positionLists)
    {
        $this->positionLists = $positionLists;
    }

    /**
     * @return array
     */
    public function getOptypeLists()
    {
        return $this->optypeLists;
    }

    /**
     * @param array $optypeLists
     */
    public function setOptypeLists($optypeLists)
    {
        $this->optypeLists = $optypeLists;
    }

    public function statsMapper($ty)
    {
        $string = "";
        if ($ty == '0') {
            $string = "<font>上架</font>";
        } else if ($ty == '1') {
            $string = "<font>下架</font>";
        }
        return $string;
    }

    public function optype($ty)
    {
        $string = "";
        $optypeList = $this->getOptypeLists();
        foreach ($optypeList as $key => $val) {
            if ($ty == $key) {
                $string = $val;
                break;
            }
        }

        return $string;
    }

    public function position($ty)
    {
        $string = "";
        $lists = $this->getPositionLists();
        foreach ($lists as $key => $val) {
            if ($ty == $key) {
                $string = $val;
                break;
            }
        }

        return $string;
    }


    public function listMapper($list)
    {
        foreach ($list as $key => $val) {
            $list[$key] = $this->infoMapper($val);
        }
        return $list;
    }

    public function infoMapper($info)
    {
        $info['positionMapper'] = $this->position($info['position']);
        $info['optypeMapper'] = $this->optype($info['optype']);
        $info['statsMapper'] = $this->statsMapper($info['stats']);
        return $info;
    }
}